
var nums="";

tongfusoft.table=function(){};

tongfusoft.table.prototype= {
	//创建表格
	creat:function(){
		 
		$("#tb_1").empty();
		var tbody=$("tbody")
		var tr;
		
		$.each(eval("Data"),function(i,v){
			
			tr+="<tr>"+
				"<td><input type='checkbox' name='ck'></td>"+
				"<td>"+v.ID+"</td>"+
				//"<td>"+v.MaterialCode+"</td>"+
				"<td>"+v.MaterialName+"</td>"+
				"<td>"+v.Size+"</td>"+
				"<td>"+v.Unit+"</td>"+
				"<td>"+v.Type+"</td>"+
				"<td>"+v.Data+"</td>"+
				"<td><a>"+v.del+"</a></td>"+
			"</tr>";
		});
		tbody.append(tr);
		
	},
	//表格查询
	search:function(){
		var oId=$("#maintable thead tr th");
		var objs=[];
		//var oId=.attr("id");
		//循环每一个 th里面的值插入到objs数组里
		$.each(oId, function(i,v) {
			var oIdLen=oId.eq(i).text();
			objs.push(oIdLen);
		});
		//创建查询text文本
		var html='';
		for (var i=0;i<objs.length;i++) {
			
			html='<div class="search">'+
            		'<div class="lay_style">'+
            			'<span class="Name_s">'+objs[1]+':</span>'+
            			'<input type="text"/ class="id-frame">'+
            		'</div>'+
            		'<div class=" lay_style">'+
            			'<span class="Name_s">'+objs[2]+':</span>'+
            			'<input type="text"/ class="wlbm-frame">'+
            		'</div>'+
            		'<div class="lay_style ">'+
            			'<span class="Name_s">'+objs[3]+':</span>'+
            			'<input type="text"/ class="wlmc-frame">'+
            		'</div>'+
					'<div class="lay_style lay_style_sz">'+
            			'<span class="Name_s">'+"数字"+':</span>'+
						'<select name="account" class="form-control">'+
						'<option>'+'>'+'</option>'+
						'<option>'+'<'+'</option>'+
						'<option>'+'='+'</option>'+
						'</select>'+
            			'<input type="text"/ class="sz-frame">'+
            		'</div>'+
            	'</div>'+
            	'<div class="search search-none">'+
            		'<div class="lay_style lay_style_gg">'+
            			'<span class="Name_s">'+objs[4]+':</span>'+
            			'<input type="text" / class="gg-frame">'+
            		'</div>'+
            		'<div class=" lay_style lay_style_lx">'+
            			'<span class="Name_s">'+objs[5]+':</span>'+
            			'<input type="text"/ class="lx-frame">'+
            		'</div>'+
            		'<div class=" lay_style_date">'+
            			'<span class="Name_date">'+objs[6]+':</span>'+
            			'<p id="datetimepicker" class="input-group date">'+
			                '<input type="text" class="form-control form-control-date" />'+
			                '<span class="input-group-addon">'+
			                	'<span class="fa fa-calendar"></span>'+
			                '</span>'+
			            '</p>'+
			            '<p class="input-group-fg" style="float:left; margin:0px 10px; line-height:25px">-</p>'+
			            '<p id="datetimepicker2" class="input-group date">'+
			                '<input type="text" class="form-control form-control-date" />'+
			                '<span class="input-group-addon">'+
			                	'<span class="fa fa-calendar"></span>'+
			                '</span>'+
			            '</p>'+
            		'</div>'+
            		'<div class="clear"></div>'+
            	'</div>';
		}
		
		$(".creat-top-r").before(html);
		
		//日期插入
		$('#datetimepicker').datetimepicker({
			icons: {
				time: 'fa fa-clock-o',
				date: 'fa fa-calendar',
				up: 'fa fa-chevron-up',
				down: 'fa fa-chevron-down',
				previous: 'fa fa-chevron-left',
				next: 'fa fa-chevron-right',
				today: 'fa fa-crosshairs',
				clear: 'fa fa-trash'
			}
		});
		$('#datetimepicker2').datetimepicker({
			icons: {
				time: 'fa fa-clock-o',
				date: 'fa fa-calendar',
				up: 'fa fa-chevron-up',
				down: 'fa fa-chevron-down',
				previous: 'fa fa-chevron-left',
				next: 'fa fa-chevron-right',
				today: 'fa fa-crosshairs',
				clear: 'fa fa-trash'
			}
		});
		
		//查询的数据拼接
		$("#search-btn").click(function(){
			var params={
				oSeaOne:$("#search-1").val(),
				oSeaTwo:$("#search-2").val(),
				oSeaThree:$("#search-3").val(),
				oSeaFour:$("#search-4").val(),
				oSeaFive:$("#search-5").val(),
				/*oSeaSix:$("#control_date").val(),
				oSeaSeven:$("#control_date2").val(),*/
			}
			//console.log(params)
			console.log($("#datetimepicker .form-control").val())
			var $from=$("#datetimepicker .form-control").val()
			var $to=$("#datetimepicker2 .form-control").val();
			var from_seconds=new Date($from.replace("-", "/").replace("-", "/")).getTime()
			var to_seconds=new Date($to.replace("-", "/").replace("-", "/")).getTime();
			if($from!="" && $to !=""){
            if(from_seconds>to_seconds){
               alert("起始日期不能大于结束日期！");
               return;
            }
            
        }
		});
	}
	
}
var b=new tongfusoft.table();
$(function(){
	//调用分页的插件
	 $.jqPaginator('#pagination2', {
	        totalPages: 5,
	        visiblePages: 3,
	        currentPage: 1,
	        prev: '<li class="prev"><a href="javascript:;">Previous</a></li>',
	        next: '<li class="next"><a href="javascript:;">Next</a></li>',
	        page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
	        onPageChange: function (num, type) {
	            $('#p2').text(type + '：' + num);
	            	//alert(num);
				 nums = "result"+num;
				//alert(nums)
				$("#tb_1").empty();
				//$('#tb_1').html('');
				b.creat();
	        }
	    });
	//创建
	b.creat();
	//查询
	b.search();
	
	
	
})
